package com.jyserver.common.AutoCode.jybaits.element.pc;

public class validator {
    public static String validInt() {
        return "var validInt= (rule, value, validator) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "            validator()\n" +
                "        } else if(!(value % 1 === 0)) {\n" +
                "            validator(new Error('请输入整数'))\n" +
                "        }\n" +
                "        validator();\n" +
                "    };\n";
    }

    public static String validInt(String str) {
        return "var validInt= (rule, value, validator) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "            validator()\n" +
                "        } else if(!(value % 1 === 0)) {\n" +
                "            validator(new Error('" + str + "'))\n" +
                "        }\n" +
                "        validator();\n" +
                "    };\n";
    }

    public static String validID() {
        return "var validID = (rule, value, callback) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "          callback()\n" +
                "        } else {\n" +
                "          let reg = /^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$/\n" +
                "          if (!reg.test(value)) {\n" +
                "            callback(new Error('身份证号码不正确'))\n" +
                "          }\n" +
                "        }\n" +
                "        callback();\n" +
                "      };\n";
    }

    public static String validID(String str) {
        return "var validID = (rule, value, callback) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "          callback()\n" +
                "        } else {\n" +
                "          let reg = /^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$/\n" +
                "          if (!reg.test(value)) {\n" +
                "            callback(new Error('" + str + "'))\n" +
                "          }\n" +
                "        }\n" +
                "        callback();\n" +
                "      };\n";
    }

    public static String validphone() {
        return " var validphone = (rule, value, callback) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "            callback()\n" +
                "        } else {\n" +
                "            let reg = /^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$/\n" +
                "            if (value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\\d{8})$/.test(value)) {\n" +
                "            } else {\n" +
                "                callback(new Error('手机号码不正确'))\n" +
                "            }\n" +
                "        }\n" +
                "        callback();\n" +
                "    };\n";
    }

    public static String validphone(String str) {
        return " var validphone = (rule, value, callback) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "            callback()\n" +
                "        } else {\n" +
                "            let reg = /^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$/\n" +
                "            if (value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\\d{8})$/.test(value)) {\n" +
                "            } else {\n" +
                "                callback(new Error('" + str + "'))\n" +
                "            }\n" +
                "        }\n" +
                "        callback();\n" +
                "    };\n";
    }

    public static String validatePass() {
        return "var validatePass = (rule, value, callback) => {\n" +
                "        if (value === '') {\n" +
                "            callback(new Error('请输入密码'));\n" +
                "        } else if(/^\\d+$/.test(value)) {\n" +
                "            callback(new Error('不能为纯数字'));\n" +
                "        }else {\n" +
                "            if (this.dataform.checkPass !== '') {\n" +
                "                this.$refs.dataform.validateField('checkPass');\n" +
                "            }\n" +
                "            callback();\n" +
                "        }\n" +
                "    };\n";
    }

    public static String checkPass() {
        return "var checkPass = (rule, value, callback) => {\n" +
                "        if (value === '') {\n" +
                "          callback(new Error('请再次输入密码'));\n" +
                "        } else if (value !== this.dataform.password) {\n" +
                "          callback(new Error('两次输入密码不一致!'));\n" +
                "        } else {\n" +
                "          callback();\n" +
                "        }\n" +
                "      };\n";
    }

    public static String validemail() {
        return "var validemail = (rule, value, callback) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "            callback()\n" +
                "        } else {\n" +
                "            let mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/\n" +
                "            if (mailReg.test(value)) {\n" +
                "                callback();\n" +
                "            } else {\n" +
                "                callback(new Error('邮箱不正确'))\n" +
                "            }\n" +
                "        }\n" +
                "        callback();\n" +
                "    };\n";
    }


    public static String validemail(String str) {
        return "var validemail = (rule, value, callback) => {\n" +
                "        if (value == '' || value == undefined) {\n" +
                "            callback()\n" +
                "        } else {\n" +
                "            let mailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/\n" +
                "            if (mailReg.test(value)) {\n" +
                "                callback();\n" +
                "            } else {\n" +
                "                callback(new Error('" + str + "'))\n" +
                "            }\n" +
                "        }\n" +
                "        callback();\n" +
                "    };\n";
    }

}
